package contest.sweek203;

import java.util.ArrayList;
import java.util.List;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/8/24 16:18
 */
public class Solution1 {

    public List<Integer> mostVisited(int n, int[] rounds) {
        int[] steps = new int[n + 1];
        steps[rounds[0]]++;
        for (int i = 1; i < rounds.length; i++) {
            int pre = rounds[i - 1] + 1;
            int cur = rounds[i];
            pre = pre > n ? pre - n : pre;
            cur = cur < pre ? cur + n : cur;
            for (int j = pre; j <= cur; j++) {
                int c = j > n ? j - n : j;
                steps[c]++;
            }
        }
        int maxS = 0;
        List<Integer> res = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            if (steps[i] > maxS) {
                maxS = steps[i];
                res.clear();
                res.add(i);
            } else if (steps[i] == maxS) {
                res.add(i);
            }
        }
        return res;
    }
}
